package com.cyou.qb.common.dao;

import java.util.HashMap;
import java.util.Map;

import org.springframework.stereotype.Component;

import com.cyou.qb.common.domain.QiangbaAdmin;
import com.cyou.qb.constants.Constants;

/**
 * <p>QbAdminDao</p>
 * <p>
 * Description:账号管理DAO
 * </p>
 *
 * @author lidongwei
 * @version 
 * @since 2012-9-20
 */
@Component
public class QbAdminDao extends MysqlBaseDao {

	/**
	 * 保存一个账户
	 * Description
	 * @author lidongwei
	 * @since 2012-10-6
	 */
	public int saveOneAdmin(QiangbaAdmin qiangbaAdmin) {
		return this.insert("saveOneAdmin", qiangbaAdmin);
	}
	/**
	 * 删除一个账户
	 * Description
	 * @author lidongwei
	 * @since 2012-10-6
	 */
	public int removeOneAdmin(int adminId) {
		return this.update("updateStatus", adminId);
	}
//	/**
//	 * 根据条件获取账户信息，并存储在分页中
//	 * Description
//	 * @author lidongwei
//	 * @since 2012-10-6
//	 */
//
//	public PaginationSupport<QiangbaAdmin> findAdminByConditions(Map conditions, int currentPage, int pageSize) {
//		return this.getPageByEntity("findAdminByConditions", conditions, currentPage, pageSize);
//	}
//	/**
//	 * 获取账户信息，并存储在分页中
//	 * Description
//	 * @author lidongwei
//	 * @since 2012-10-6
//	 */
//
//	public PaginationSupport<QiangbaAdmin> findPage(int currentPage, int pageSize) {
//		return this.getPageByEntity("findAdminByConditions", null, currentPage, pageSize);
//	}
	/**
	 * 根据账户id获取一个账户
	 * Description
	 * @author lidongwei
	 * @since 2012-10-6
	 */

	public QiangbaAdmin findOneAmind(int adminId) {
		return this.getUniqueOne("findOneAdmin", adminId);
	}
	/**
	 * 更新账户信息
	 * Description
	 * @author lidongwei
	 * @since 2012-10-6
	 */

	public void updateAccount(QiangbaAdmin qiangbaAdmin) {
		this.update("updateAccount", qiangbaAdmin);
	}

	/**
	 * 修改账户锁定和未锁定状态
	 * Description RestorePassword ：1 LockAccount:2 unLockAccount:3
	 * @author lidongwei
	 * @since 2012-9-20
	 */
	public void updateOneP(int adminId, int pTag) {
		Map map = new HashMap();
		map.put("adminId", adminId);
		switch (pTag) {
		case 2:
			map.put("valid", 0);
			break;
		case 3:
			map.put("valid", 1);
			break;
		}
		this.update("updateBase", map);

	}
	/**
	 * 重置账户密码
	 * Description
	 * @author lidongwei
	 * @since 2012-10-6
	 */
	public void resetPassword(int adminId)
	{
		Map map = new HashMap();
		map.put("adminId", adminId);
		map.put("password", Constants.ADMIN_USER_DEFAULT_PWD);
		this.update("updateBase", map);
	}
	/**
	 * 判断登陆
	 * Description
	 * @author lidongwei
	 * @since 2012-10-6
	 */
	public QiangbaAdmin checkLogin(Map<String,Object> map)
	{
	   return (QiangbaAdmin)this.getFirstOne("findAdminByConditions", map);
	}
	/**
	 * 
	 */
	public int updateBase(QiangbaAdmin qiangbaAdmin){
		return this.update("updateBase", qiangbaAdmin);
	}

}
